package CA;
import java.io.File;
import java.util.ArrayList;
import java.util.List;

import StringComparision.StringDistances;

import junit.framework.TestCase;


public class MissingInfo_Test extends TestCase {

	private final String MainExaminLocation = System.getProperty("user.dir") + "/UnitTestData/";
	
	protected void setUp() throws Exception {
		super.setUp();
	}

	protected void tearDown() throws Exception {
		super.tearDown();
	}
	
	//
	
	public void testisMissingModule()
	{
		Helper h = new Helper();
		assertFalse(h.isMissingModule("Fred"));
		assertTrue(h.isMissingModule("^*^Fred"));
		assertFalse(h.isMissingModule("F^*^red"));
	}
	
	
	public void testgetMissingModuleInfoByFile()
	{
		String compareFile = "C:/SignatureOutput/noscan/UnitTests/missingStack/missingStackFolder1/";
		Helper h = new Helper();
		File f0=new File(compareFile+"0.txt"); // 0 errors
		File f1=new File(compareFile+"1.txt"); // 1 errors
		File f2=new File(compareFile+"2.txt"); // 2 errors
		File f3=new File(compareFile+"3.txt"); // 3 errors
		File f4=new File(compareFile+"4.txt"); // 4 errors
		assertEquals(0, h.getMissingModuleInfoByFile(f0));
		assertEquals(1, h.getMissingModuleInfoByFile(f1));
		assertEquals(2, h.getMissingModuleInfoByFile(f2));
		assertEquals(3, h.getMissingModuleInfoByFile(f3));
		assertEquals(4, h.getMissingModuleInfoByFile(f4));
		
	}
	
	
	
	public void testAnalyzeMissingOnly()
	{
		String compareFile = MainExaminLocation+"/MissingStackRemoveAdd/files/";
		// Test before missing crash information
		StringDistances sd = new StringDistances();	
		Helper h = new Helper();
		CrashSuper cs = new CrashSuper();
		List<FileInfo> fileList = new ArrayList<FileInfo>();
		fileList=cs.getFileList(compareFile);
		cs.BuildFileData(fileList, compareFile, false);
	
		
		// Include missing crash information
		assertEquals(h.getTotalLinesInAllFiles(fileList, false),820);
		assertEquals(h.getTotalLinesMissingCrashInfoInAllFiles(fileList, false),4);
		assertEquals(h.getTotalNumberOfFolders(fileList, false),3);
		assertEquals(h.getTotalNumberOfFoldersWithMissingCrashInfo(fileList, false),2);
		// ADD MORE......
		
		// Exclude missing crash information
		assertEquals(h.getTotalLinesInAllFiles(fileList, true),616);
		assertEquals(h.getTotalLinesMissingCrashInfoInAllFiles(fileList, true),0);
		assertEquals(h.getTotalNumberOfFolders(fileList, true),1);
		assertEquals(h.getTotalNumberOfFoldersWithMissingCrashInfo(fileList, true),0);
		// ADD MORE......
	
		
	}
	
	
	// Check to see if a is missing stack information
	public void testIsFileMissingStackInfo()
	{
		String compareFile = MainExaminLocation+"/MissingStackRemoveAdd/files/";
		Helper h = new Helper();
		StringDistances sd = new StringDistances();	
		CrashSuper cs = new CrashSuper();
		List<FileInfo> fileList = new ArrayList<FileInfo>();
		fileList=cs.getFileList(compareFile);
		cs.BuildFileData(fileList, compareFile, false);
		
		
		assertTrue(h.isFileMissingStackInfo(fileList.get(h.getArrayIndex(fileList, "File1"))));
		assertTrue(h.isFileMissingStackInfo(fileList.get(h.getArrayIndex(fileList, "File2"))));
		assertFalse(h.isFileMissingStackInfo(fileList.get(h.getArrayIndex(fileList, "File3"))));
	}
	


	// isMissingModulesByScan
	public void testIsFileContainMissingInfoLines()
	{
		String compareFile = MainExaminLocation+"missingStack/missingStackFolder3/file2/";
		Helper h = new Helper();
		StringDistances sd = new StringDistances();	
		CrashSuper cs = new CrashSuper();
		List<FileInfo> fileList = new ArrayList<FileInfo>();
		fileList=cs.getFileList(compareFile);
		cs.BuildFileData(fileList, compareFile, false);
		
		assertFalse(h.isFileContainMissingInfoLines(compareFile+"0.txt"));
		assertTrue(h.isFileContainMissingInfoLines(compareFile+"1.txt"));
		assertTrue(h.isFileContainMissingInfoLines(compareFile+"2.txt"));
		assertTrue(h.isFileContainMissingInfoLines(compareFile+"3.txt"));
		assertTrue(h.isFileContainMissingInfoLines(compareFile+"4.txt"));
			
		assertFalse(h.isFileContainMissingInfoLines(compareFile+"0-Copy(2).txt"));
		assertFalse(h.isFileContainMissingInfoLines(compareFile+"0-Copy.txt"));
		
		
		
	}
	
	// missingStackFolder4-InjectMissing
	
	

	
	
	
}
